<template>
  <el-card>
    <div slot="header" class="header">
      <span>销售额类别占比</span>
      <el-radio-group v-model="radio1" size="mini">
        <el-radio-button label="全部渠道" />
        <el-radio-button label="线上" />
        <el-radio-button label="门店" />
      </el-radio-group>
    </div>
    <div ref="charts" class="charts" /> <div />
  </el-card>
</template>

<script>
import * as echarts from 'echarts'
export default {
  name: 'Cateory',
  data() {
    return {
      radio1: '全部渠道'
    }
  },
  mounted() {
    const charts = echarts.init(this.$refs.charts)
    charts.setOption({
      tooltip: {
        trigger: 'item'
      },
      title: {
        text: '视频',
        subtext: 1048,
        left: 'center',
        top: 'center'
      },
      series: [
        {
          name: 'Access From',
          type: 'pie',
          radius: ['40%', '80%'],
          avoidLabelOverlap: false,
          itemStyle: {
            borderRadius: 10,
            borderColor: '#fff',
            borderWidth: 2
          },
          labelLine: {
            show: true
          },
          data: [
            { value: 1048, name: '视频广告' },
            { value: 735, name: '联盟广告' },
            { value: 580, name: '邮件营销' },
            { value: 484, name: '直接访问' },
            { value: 300, name: '搜索引擎' }
          ],
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
          }
        }
      ]
    })
    // 绑定上事件
    charts.on('mouseover', (params) => {
      const { name, value } = params
      charts.setOption({
        title: {
          text: name,
          subtext: value
        }
      })
    })
  }
}
</script>

<style  scoped>
.header{
    display: flex;
    align-items: center;
    position: relative;
}

.el-radio-group{
    position: absolute;
    right: 0;
}

.charts{
    height: 250px;
}
 </style>

